/*
 * @Author: huangyingli
 * @Date: 2023-02-23 00:11:52
 * @LastEditors: huangyingli
 * @LastEditTime: 2023-02-23 13:12:35
 * @Description:
 */
import { nodeResolve } from '@rollup/plugin-node-resolve';
import commonjs from '@rollup/plugin-commonjs';
import json from '@rollup/plugin-json';
import postcss from 'rollup-plugin-postcss';
import babel from '@rollup/plugin-babel';
import fs from 'fs';

const components = fs.readdirSync('./src');

// babel配置
const babelOptions = {
  presets: ['@babel/preset-react'],
  extensions: ['.js', '.jsx', '.ts', '.tsx', '.scss'],
  exclude: 'node_modules/**',
  babelHelpers: 'bundled',
};

export default components
  .filter((filename) => /\.js$/.test(filename))
  .map((filename) => {
    return {
      input: `./src/${filename}`,
      output: {
        file: `dist/${filename}`,
        format: 'cjs',
      },
      plugins: [
        // nodeResolve({
        //   jsnext: true,
        //   main: true,
        //   browser: true,
        // }),
        // commonjs({
        //   include: ['node_modules/**'],
        // }),
        // json(),
        postcss({
          extract: false, //true：分离出css文件，false：会在style里插入css
        }),
        babel({ babelHelpers: 'bundled' }),
      ],
    };
  });
